package com.iloomo.util;

import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class JsonUtil {
    public Map<String,String> jsonToMap(String jsonString){
        Map<String,String> map = new HashMap<String, String>();
        JSONObject json = JSONObject.fromObject(jsonString);
        Iterator iterator = json.keys();
        while(iterator.hasNext()) {
            String key = (String) iterator.next();
            String value = json.getString(key);
            map.put(key,value);
        }
        return map;
    }
    public Map<String,String> jsonObjToMap(JSONObject json){
        Map<String,String> map = new HashMap<String, String>();
        Iterator iterator = json.keys();
        while(iterator.hasNext()) {
            String key = (String) iterator.next();
            String value = json.getString(key);
            map.put(key,value);
        }
        return map;
    }
}
